namespace mecs {

    export class EntityUtil {

        /** 某个实体，拥有参数中全部组件 */
        static hasCompByCls(entity: BaseEntity, comps: (typeof BaseComp)[]) {
            for (let i = 0; i < comps.length; i++) {
                let cn = comps[i]['NAME'] || comps[i]['name'];
                if (!entity.hasComp(cn)) {
                    return false;
                }
            }
            return true;
        }
        /** 某个实体，拥有参数中全部组件 */
        static hasComp(entity: BaseEntity, compNames: string[]) {
            for (let i = 0; i < compNames.length; i++) {
                let cn = compNames[i];
                if (!entity.hasComp(cn)) {
                    return false;
                }
            }
            return true;
        }

        /** 某个实体，没有参数中所有组件 */
        static notCompByCls(entity: BaseEntity, comps: (typeof BaseComp)[]) {
            for (let i = 0; i < comps.length; i++) {
                let cn = comps[i]['NAME'] || comps[i]['name'];
                if (entity.hasComp(cn)) {
                    return false;
                }
            }
            return true;
        }
        /** 某个实体，没有参数中所有组件 */
        static notComp(entity: BaseEntity, compNames: string[]) {
            for (let i = 0; i < compNames.length; i++) {
                let cn = compNames[i];
                if (entity.hasComp(cn)) {
                    return false;
                }
            }
            return true;
        }

        /** 某个实体，拥有参数中任一组件 */
        static anyCompByCls(entity: BaseEntity, comps: (typeof BaseComp)[]) {
            for (let i = 0; i < comps.length; i++) {
                let cn = comps[i]['NAME'] || comps[i]['name'];
                if (entity.hasComp(cn)) {
                    return true;
                }
            }
            return false;
        }
        /** 某个实体，拥有参数中任一组件 */
        static anyComp(entity: BaseEntity, compNames: string[]) {
            for (let i = 0; i < compNames.length; i++) {
                let cn = compNames[i];
                if (entity.hasComp(cn)) {
                    return true;
                }
            }
            return false;
        }

        /** 通过缓存创建实体 */
        static createEntityByCache(world: BaseWorld, data: ICacheEntity) {
            let entity = new BaseEntity(world, data.entityName, data.sid);
            if (data.comps) {
                for (let c in data.comps) {
                    let comp = data.comps[c];
                    let tc = world.compCreater.createCompByCache(c, comp)
                    entity.addComp(tc, true)
                }
            }
            return entity;
        }
    }
}